package com.dataseek.iot.mysql.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dataseek.iot.core.util.DateUtil;
import com.dataseek.iot.mysql.entity.DeviceLog;
import com.dataseek.iot.mysql.entity.DeviceRecord;
import com.dataseek.iot.mysql.mapper.AlarmLogMapper;
import com.dataseek.iot.mysql.service.IAlarmLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author cc
 * @since 2021-09-23
 */
@Service
public class AlarmLogServiceImpl extends ServiceImpl<AlarmLogMapper, DeviceLog> implements IAlarmLogService {

    /**
     * 获取过去几天的报警信息
     * @param code
     * @param num
     * @return
     */
    public List<DeviceLog> getLogInPast(String code, Integer num){
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("device_code", code);
        wrapper.gt("create_time", DateUtil.getPastDate(num));
        wrapper.orderByAsc("create_time");
        return this.list(wrapper);
    }

    /**
     * 获取未处理设备报警日志列表
     * @param code
     * @return
     */
    public List<DeviceLog> getAlarmLog(String code) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("device_code", code);
        wrapper.eq("handle_status", 0);
        wrapper.orderByAsc("create_time");
        return this.list(wrapper);
    }
}
